

//
//  VideoTableViewCell.m
//  LuckyRadio
//
//  Created by JiaRui on 15/11/20.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "VideoTableViewCell.h"
#define kw self.frame.size.width
#define kh self.frame.size.height

@implementation VideoTableViewCell

-(void)dealloc
{
    [_bigNumLabel release];
    [_smallNumLabel release];
    [_titleLabel release];
    [_MVView release];
    [_line release];
    [_play release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.bigNumLabel = [[UILabel alloc]init];
        self.line = [[UIView alloc]init];
        [self.bigNumLabel addSubview:self.line];
        self.smallNumLabel= [[UILabel alloc]init];
        self.titleLabel = [[UILabel alloc]init];
        self.MVView = [[UIImageView alloc]init];
        self.play = [[UIImageView alloc]init];  
        [self.contentView addSubview:self.bigNumLabel];
        [self.contentView addSubview:self.smallNumLabel];
        [self.contentView addSubview:self.titleLabel];
        [self.MVView addSubview:self.play];
        [self.contentView addSubview:self.MVView];
            for (int i = 0; i < 4; i++)
            {
                UILabel * label = [[UILabel alloc]init];
                label.tag = 1266 + i;
                [self.contentView addSubview:label];
                [label release];
            }
        [_bigNumLabel release];
        [_smallNumLabel release];
        [_titleLabel release];
        [_MVView release];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.bigNumLabel.frame = CGRectMake(10, 5, 60, 60);
    self.line.frame =  CGRectMake(0, 57, 60, 1);
    self.line.backgroundColor = [UIColor lightGrayColor];
//    self.bigNumLabel.backgroundColor = [UIColor grayColor];
//    self.smallNumLabel.backgroundColor = [UIColor greenColor];
    self.smallNumLabel.frame = CGRectMake(10, 65, 60, 30);
    self.titleLabel.frame = CGRectMake(80, 5, kw - 20 - 70, 60);
//    self.titleLabel.backgroundColor = [UIColor yellowColor];
    self.MVView.frame = CGRectMake(10, 110, kw - 20, 200);
    self.play.frame = CGRectMake((kw - 20)/ 2 - 40, 200 / 2 - 40, 80, 80);
//    self.play.alpha = 0.7;
    [self.play setImage:[UIImage imageNamed:@"mv_player"]];
    self.MVView.userInteractionEnabled = YES;
    self.MVView.backgroundColor = [UIColor purpleColor];
    
    for (int i = 0; i < 4; i++) {
        UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
        label.frame = CGRectMake(80 + i * (kw - 20 - 50) / 4 + 8 * i, 70, (kw - 20 - 80) / 4, 30);
        label.layer.cornerRadius = 15;
        label.clipsToBounds = YES;
    }
}
-(void)setModel:(VideoModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    if (model.tagArray.count == 4)
    {
        for (int i = 0; i < 4; i++) {
            UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
            label.text = [model.tagArray[i] tagName];
            NSString * string = [NSString stringWithFormat:@"%@", [model.tagArray[i] tagColor]];
            NSString * str = [string substringFromIndex:4];
            NSArray *array = [str componentsSeparatedByString:@","];
            CGFloat R = [array[0] floatValue] / 255.0;
            CGFloat G = [array[1] floatValue] / 255.0;
            CGFloat B = [array[2] floatValue] / 255.0;
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor colorWithRed:R green:G blue:B alpha:1];
            self.bigNumLabel.textColor = label.backgroundColor;

        }
    }else if (model.tagArray.count == 3)
    {
        for (int i = 0; i < 3; i++) {
            UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
            label.text = [model.tagArray[i] tagName];
            NSString * string = [NSString stringWithFormat:@"%@", [model.tagArray[i] tagColor]];
            NSString * str = [string substringFromIndex:4];
            NSArray *array = [str componentsSeparatedByString:@","];
            CGFloat R = [array[0] floatValue] / 255.0;
            CGFloat G = [array[1] floatValue] / 255.0;
            CGFloat B = [array[2] floatValue] / 255.0;
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor colorWithRed:R green:G blue:B alpha:1];
            self.bigNumLabel.textColor = label.backgroundColor;

        }

    }else if (model.tagArray.count == 2)
    {
        for (int i = 0; i < 2; i++) {
            UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
            label.text = [model.tagArray[i] tagName];
            NSString * string = [NSString stringWithFormat:@"%@", [model.tagArray[i] tagColor]];
            NSString * str = [string substringFromIndex:4];
            NSArray *array = [str componentsSeparatedByString:@","];
            CGFloat R = [array[0] floatValue] / 255.0;
            CGFloat G = [array[1] floatValue] / 255.0;
            CGFloat B = [array[2] floatValue] / 255.0;
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor colorWithRed:R green:G blue:B alpha:1];
            self.bigNumLabel.textColor = label.backgroundColor;

        }

    }else if (model.tagArray.count == 1)
    {
        for (int i = 0; i < 1; i++) {
            UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
            label.text = [model.tagArray[i] tagName];
            NSString * string = [NSString stringWithFormat:@"%@", [model.tagArray[i] tagColor]];
            NSString * str = [string substringFromIndex:4];
            NSArray *array = [str componentsSeparatedByString:@","];
            CGFloat R = [array[0] floatValue] / 255.0;
            CGFloat G = [array[1] floatValue] / 255.0;
            CGFloat B = [array[2] floatValue] / 255.0;
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor colorWithRed:R green:G blue:B alpha:1];
            self.bigNumLabel.textColor = label.backgroundColor;

        }

    }else
    {
        for (int i = 0; i < 5; i++) {
            UILabel * label = (UILabel *)[self.contentView viewWithTag:1266 + i];
            label.text = @"";
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];
            self.bigNumLabel.textColor = [UIColor cyanColor];
        }
    }
    NSString * str = [NSString stringWithFormat:@"%@", model.title];
    NSArray *array = [str componentsSeparatedByString:@"/"]; //从字符A中分隔成2个元素的数组
    self.bigNumLabel.text = array[0];
    self.bigNumLabel.textAlignment = NSTextAlignmentCenter;
    self.bigNumLabel.font = [UIFont systemFontOfSize:35 weight:1];
    self.smallNumLabel.text = array[1];
    self.smallNumLabel.textAlignment = NSTextAlignmentCenter;
    self.smallNumLabel.font = [UIFont systemFontOfSize:19];
    self.titleLabel.text = model.desc;
    self.titleLabel.numberOfLines = 2;
    [self.MVView sd_setImageWithURL:[NSURL URLWithString:model.bigPicUrl] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
}



+(VideoTableViewCell *)VideoTableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIden = @"cellIden";
    VideoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIden];
    if (!cell) {
        cell = [[VideoTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIden];
    }
    return cell;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
